package com.stox.ui.javafx.charting.model.plot;

import java.util.ArrayList;
import java.util.List;

import com.stox.model.AbstractModel;
import com.stox.ui.javafx.charting.model.uiunit.AbstractUiUnit;
import com.stox.ui.javafx.charting.strategy.Strategy;
import com.stox.ui.javafx.charting.widget.Chart;

public abstract class AbstractPlot<T, 
			W extends Chart<U>, 
			V extends AbstractUiUnit<T,W, V, U>, 
			U extends AbstractPlot<T,W,V,U>>{
	
	private W chart;
	
	private final AbstractModel model;
	
	private final List<T> data = new ArrayList<>();
	
	private final List<V> uiUnits = new ArrayList<>();

	private Strategy<V> colorStrategy;
	
	private Strategy<V> widthStrategy;
	
	private Strategy<V> heightStrategy;
	
	protected double highest = Double.MIN_VALUE;
	
	protected double lowest = Double.MAX_VALUE;
	
	public AbstractPlot(AbstractModel model) {
		this.model = model;
	}
	
	protected abstract void createUiUnits();

	public void update() {
		reset();
	}
	
	public abstract void paint();
	
	public void reset() {
		highest = Double.MIN_VALUE;
		lowest = Double.MAX_VALUE;
	}
	
	public AbstractModel getModel() {
		return model;
	}
	
	public W getChart() {
		return chart;
	}

	public void setChart(W chart) {
		this.chart = chart;
	}

	public double getHighest() {
		return highest;
	}

	public double getLowest() {
		return lowest;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data.clear();
		uiUnits.clear();
		this.data.addAll(data);
		createUiUnits();
	}

	public List<V> getUiUnits() {
		return uiUnits;
	}

	public Strategy<V> getColorStrategy() {
		return colorStrategy;
	}

	public void setColorStrategy(
			Strategy<V> colorStrategy) {
		this.colorStrategy = colorStrategy;
	}

	public Strategy<V> getWidthStrategy() {
		return widthStrategy;
	}

	public void setWidthStrategy(Strategy<V> widthStrategy) {
		this.widthStrategy = widthStrategy;
	}

	public Strategy<V> getHeightStrategy() {
		return heightStrategy;
	}

	public void setHeightStrategy(Strategy<V> heightStrategy) {
		this.heightStrategy = heightStrategy;
	}
	
}
